package com.shop2cn.iapi.sqpayment.testcase;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.paymentproxy.parameter.RefundQueryBean;
import com.ymatou.paymentproxy.service.RefundQueryCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.sqlwapper.SQPayGateWayWapper;

/**
 * 退款查询接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_RefundQuery {
	private static RefundQueryBean refundqueryBean;
	private static RefundQueryCall refundqueryCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("退款查询接口");
	}

	@Before
	public void caseUp() {
		refundqueryBean = new RefundQueryBean();
		refundqueryCall = new RefundQueryCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(refundqueryCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_RefundQuery_001() {
		Logger.start(true, "查询ApproveStatus=0的一条");
		try {
			List<Map> list = new SQPayGateWayWapper().queryRefundrequestByApproveStatus(0);
			if (list.size() >= 1) {
				Map item = list.get(0);
				String orderid = item.get("OrderId").toString();
				refundqueryBean.setKey(orderid);
				refundqueryBean.setPageSize(20);
				refundqueryBean.setPageIndex(1);
				refundqueryBean.setApproveStatus(0);
				refundqueryCall.setData(refundqueryBean);
				refundqueryCall.callService();

				String response = refundqueryCall.getReturnData();
				Logger.comment("refundqueryCall send:" + refundqueryCall.getEntityString());
				Logger.comment("refundqueryCall response:" + response);

				Logger.verifyEquals(true, response.contains(orderid), "验证返回");
				Logger.verifyEquals(true, response.contains("\"ApproveStatus\":0"), "验证返回");

			} else {
				Logger.comment("数据库未查到合适数据。");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_RefundQuery_002() {
		Logger.start(true, "查询ApproveStatus=1的一条");
		try {
			List<Map> list = new SQPayGateWayWapper().queryRefundrequestByApproveStatus(1);
			if (list.size() >= 1) {
				Map item = list.get(0);
				String orderid = item.get("OrderId").toString();
				refundqueryBean.setKey(orderid);
				refundqueryBean.setPageSize(20);
				refundqueryBean.setPageIndex(1);
				refundqueryBean.setApproveStatus(1);
				refundqueryCall.setData(refundqueryBean);
				refundqueryCall.callService();

				String response = refundqueryCall.getReturnData();
				Logger.comment("refundqueryCall send:" + refundqueryCall.getEntityString());
				Logger.comment("refundqueryCall response:" + response);

				Logger.verifyEquals(true, response.contains(orderid), "验证返回");
				Logger.verifyEquals(true, response.contains("\"ApproveStatus\":1"), "验证返回");

			} else {
				Logger.comment("数据库未查到合适数据。");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_RefundQuery_003() {
		Logger.start(true, "查询RefundStatus=0的一条");
		try {
			List<Map> list = new SQPayGateWayWapper().queryRefundrequestByApproveStatusAndRefundStatus(0, 4);
			if (list.size() >= 1) {
				Map item = list.get(0);
				String orderid = item.get("OrderId").toString();
				refundqueryBean.setKey(orderid);
				refundqueryBean.setPageSize(20);
				refundqueryBean.setPageIndex(1);
				refundqueryBean.setApproveStatus(0);
				refundqueryCall.setData(refundqueryBean);
				refundqueryCall.callService();

				String response = refundqueryCall.getReturnData();
				Logger.comment("refundqueryCall send:" + refundqueryCall.getEntityString());
				Logger.comment("refundqueryCall response:" + response);

				Logger.verifyEquals(true, response.contains(orderid), "验证返回");
				Logger.verifyEquals(true, response.contains("\"ApproveStatus\":0"), "验证返回");
				Logger.verifyEquals(true, response.contains("\"RefundStatus\":4"), "验证返回");
			} else {
				Logger.comment("数据库未查到合适数据。");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_RefundQuery_005() {
		Logger.start(true, "查询ApproveStatus=0的多条");
		try {
			refundqueryBean.setKey("");
			refundqueryBean.setPageSize(20);
			refundqueryBean.setPageIndex(1);
			refundqueryBean.setApproveStatus(0);
			refundqueryCall.setData(refundqueryBean);
			refundqueryCall.callService();

			String response = refundqueryCall.getReturnData();
			Logger.comment("refundqueryCall send:" + refundqueryCall.getEntityString());
			Logger.comment("refundqueryCall response:" + response);
			Logger.verifyEquals(true, response.contains("\"ApproveStatus\":0"), "验证返回");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_RefundQuery_006() {
		Logger.start(true, "查询ApproveStatus=1的多条");
		try {
			refundqueryBean.setKey("");
			refundqueryBean.setPageSize(20);
			refundqueryBean.setPageIndex(1);
			refundqueryBean.setApproveStatus(1);
			refundqueryCall.setData(refundqueryBean);
			refundqueryCall.callService();

			String response = refundqueryCall.getReturnData();
			Logger.comment("refundqueryCall send:" + refundqueryCall.getEntityString());
			Logger.comment("refundqueryCall response:" + response);
			Logger.verifyEquals(true, response.contains("\"ApproveStatus\":1"), "验证返回");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}